import {leaderTypeObj} from "@/assets/js"
import {objToStr} from "@/utils"

export const headerList = [
    {
        prop: "name",
        label: "合同名称",
        type: "text",
        width: "200",
        required: true,
        
    },{
        prop: "review_status",
        label: "状态",
        type: "text",
        width: "180",
        required: false,
        noSort: true,
    },{
        prop: "contract_code",
        label: "合同编号",
        type: "text",
        width: "150",
        required: false,
        
    },{
        prop: "start_time",
        label: "开始日期",
        type: "text",
        width: "150",
        required: false,
        
    },{
        prop: "end_time",
        label: "终止日期",
        type: "text",
        width: "150",
        required: false,
        
    },{
        prop: "leader_id",
        label: "负责人",
        type: "number",
        width: "130",
        required: true,
    },{
        prop: "departments_id",
        label: "所属科室",
        type: "number",
        width: "180",
        required: true,
        
    },{
        prop: "complete_id",
        label: "完成人",
        type: "number",
        width: "160",
        required: false,
        
    },{
        prop: "contract_type",
        label: "合同类型",
        type: "text",
        width: "150",
        required: true,
        
    },{
        prop: "project_source",
        label: "合同来源",
        type: "text",
        width: "180",
        required: false,
        
    },{
        prop: "leader_type",
        label: "负责人类型",
        type: "text",
        width: "180",
        required: true,
        
    },{
        prop: "contract_amount",
        label: "合同金额",
        unit: "(万元)",
        type: "number",
        width: "180",
        required: true,
        
    },{
        prop: "account",
        label: "财务账号",
        type: "text",
        width: "180",
        required: false,
        
    },{
        prop: "contract_situation",
        label: "合同履行情况",
        type: "textarea",
        width: "300",
        required: false,
        
    },{
        prop: "first_party_name",
        label: "甲方名称",
        type: "text",
        width: "200",
        required: false,
        
    },{
        prop: "first_party_person",
        label: "甲方代表人",
        type: "text",
        width: "200",
        required: false,
        
    },{
        prop: "first_party_type",
        label: "甲方类别",
        type: "text",
        width: "200",
        required: false,
        
    }
]

export let editForm = {
    id:'',
    name:'',
    contract_code:'',
    start_time:'',
    end_time:'',
    leader_id:'',
    departments_id:'',
    complete_id:'',
    complete_name:"",
    contract_type:'',
    project_source:'',
    leader_type:'',
    contract_amount:'',
    account:'',
    contract_situation:'',
    first_party_name:'',
    first_party_person:'',
    first_party_type:'',
    leader_info:{}
}

export const contractType = [
    {
        label: '技术开发',
        value: 1
    },{
        label: '技术服务',
        value: 2
    },{
        label: '技术转让',
        value: 3
    },{
        label: '技术咨询',
        value: 4
    },{
        label: '知识产权归属',
        value: 5
    }
]

export const contractTypeObj = {
    1:'技术开发',
    2:'技术服务',
    3:'技术转让',
    4:'技术咨询',
    5:'知识产权归属',
}

export const dataFn = (data,tableHeade) => {
    let tabStr = ''
    data.forEach((item, index) => {
        let tabRowStr = "";
        tabStr += `<tr>`;
        for (let i = 0; i < tableHeade.length; i++ ) {
            const key = tableHeade[i]
            if (key === 'departments_id') {
                tabRowStr += `<td>${item.department?item.department.name:''}</td>`;
            }else if(key === 'complete_id'){
                tabRowStr += `<td>${objToStr(item.complete_name)}</td>`;
            }else if(key === 'review_status'){
              tabRowStr += `<td>${item.status}${item.review.review_comment ? (':' + item.review.review_comment): ''}</td>`;
            }else if(key === 'leader_id'){
              tabRowStr += `<td>${item.leader_info?item.leader_info.name:''}</td>`;
            }else if(key === 'leader_type'){
              tabRowStr += `<td>${leaderTypeObj[item.leader_type] || ''}</td>`;
            }else if(key === 'contract_type'){
              tabRowStr += `<td>${contractTypeObj[item.contract_type] || ""}</td>`;
            }else {
              tabRowStr += `<td>${item[key] || ''}</td>`;
            }
        }
        tabStr += tabRowStr;
        tabStr += "</tr>";
    });
    return tabStr
}